﻿using CurrentUserDemo.Api.Extensions;
using CurrentUserDemo.Api.Infrastructures.Claims;
using CurrentUserDemo.Domain.CurrentUsers;

namespace CurrentUserDemo.Api.Infrastructures.CurrentUsers;

public class CurrentUser : ICurrentUser
{
    private readonly ICurrentPrincipalAccessor _principalAccessor;

    public CurrentUser(ICurrentPrincipalAccessor principalAccessor)
    {
        _principalAccessor = principalAccessor;
    }

    public int? Id => _principalAccessor.Principal?.FindUserId();

    public int? GetUserId()
    {
        return _principalAccessor.Principal?.FindUserId();
    }

    public string? GetUserName()
    {
        return _principalAccessor.Principal?.FindUserName();
    }
}